//
//  AdAnalyVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/8.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "AdAnalyVC.h"


#import "ADCustomCell.h"
#import "TodoHttpManager.h"
#import "ADHeaderView.h"
@interface AdAnalyVC ()<UITableViewDelegate,UITableViewDataSource>

{
    NSString *adStr;
    NSString *phoneStr;
    NSString *visitStr;
    NSString *jiaoStr;
}
@property(nonatomic,strong)UITableView *tabView;
@property(nonatomic,strong)ADHeaderView *adHeader;
@property(nonatomic,strong)NSMutableDictionary *zoDic;
@property(nonatomic,strong)NSMutableDictionary *tDic;
@property(nonatomic,strong)NSMutableArray *musArr;
@property(nonatomic,strong)NSArray *firstArr;
@end

@implementation AdAnalyVC
-(void)viewWillAppear:(BOOL)animated
{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDManagerSecondADBiao:) name:TDManagerSecondADBiao object:nil];
    [_manager userManagerSecongADBiao];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDManagerSecondADTu:) name:TDManagerSecondADTu object:nil];
    [_manager userManagerSecondADTu];
    
}
-(void)didTDManagerSecondADTu:(NSNotification *)no
{
    if (no.object != 0)
    {
        [_tabView reloadData];
    }
}
-(void)didTDManagerSecondADBiao:(NSNotification *)notif
{
    if (notif.object != 0)
    {
        _zoDic = [notif.object objectForKey:@"data"];
       
        adStr = [_zoDic objectForKey:@"all_money"];
        phoneStr = [_zoDic objectForKey:@"c_bl"];
        visitStr = [_zoDic objectForKey:@"v_bl"];
        jiaoStr = [_zoDic objectForKey:@"d_bl"];

        _firstArr = [NSMutableArray arrayWithObjects:adStr,phoneStr,visitStr,jiaoStr, nil];
        [_tabView reloadData];
    }
    
    
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDManagerSecondADBiao object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:TDManagerSecondADTu object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = BgColor;
    
    _manager = [TodoHttpManager sharedManager];
    _zoDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _tDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _firstArr = [NSArray array];
    _musArr = [NSMutableArray arrayWithObjects:@"广告费用总额( 万元)",@"来电费效比(元/组)",@"来访费效比(元/组)",@"成交费效比(%)", nil];

    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT-45-LL_TabbarHeight-LL_StatusBarAndNavigationBarHeight) style:UITableViewStylePlain];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 40;
    _tabView.tableHeaderView = self.adHeader;
    _tabView.backgroundColor = BgColor;
   // _tabView.tableFooterView = [[UIView alloc] initWithFrame:CGSizeZero];
    
    [self.view addSubview:_tabView];
    
    _tabView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(guangGaoRefresh)];
    
}

-(ADHeaderView *)adHeader
{
    if (_adHeader)
    {
        return _adHeader;
    }
    _adHeader = [[ADHeaderView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, 250)];
    return _adHeader;
}

-(void)guangGaoRefresh
{
      [_manager userManagerSecongADBiao];
    [self.tabView.mj_header endRefreshing];
}




#pragma mark -TableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Cell";
    ADCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell)
    {
        cell = [[ADCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
    }
    if ([cell isKindOfClass:[ADCustomCell class]])
    {
        if (_firstArr.count != 0)
        {
           
            cell.grayLab.text = _firstArr[indexPath.row];
        }
    }
    

    cell.orageLab.text = _musArr[indexPath.row];

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}













- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
